package cn.zn.modules.zzsys.cur.controller;

import cn.zn.framework.common.utils.PageInUtils;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.zzsys.cur.entity.BasisWappEntity;
import cn.zn.modules.zzsys.cur.service.WappService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;


/**
 * 小程序信息
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2020-03-17 10:37:31
 */
@RestController
@RequestMapping("zzsys/wapp")
public class WappController {

    @Autowired
    private WappService wappService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("zzsys:wapp:list")
    public R list(PageInUtils<BasisWappEntity> pageIn) {

        BasisWappEntity wapp = new BasisWappEntity();
        PageUtils pageUtils = wappService.queryPage(wapp, pageIn.getPageObj());

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("zzsys:wapp:info")
    public R info(@PathVariable("id") Long id) {
            BasisWappEntity wapp = wappService.getById(id);

        return R.ok().put("wapp", wapp);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("zzsys:wapp:save")
    public R save(@RequestBody BasisWappEntity wapp) {
            wappService.save(wapp);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("zzsys:wapp:update")
    public R update(@RequestBody BasisWappEntity wapp) {
            wappService.updateById(wapp);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("zzsys:wapp:delete")
    public R delete(@RequestBody Long[] ids) {
            wappService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
